Difficult to replicate objects (object Customer) on the list? [migrated]

Posted by gandolf on Programmers See other posts from Programmers or by gandolf
Published on 2013-11-06T10:15:03Z Indexed on 2013/11/06 16:11 UTC
Read the original article Hit count: 80

Filed under:

I wrote a program that does work with files like delete and update, store, and search And all customers But I have a problem with the method is LoadAll Once the data are read from the file and then Deserialize the object becomes But when I want to save the list of objects in the list are repeated. How can I prevent the duplication in this code?

var customerStr = File.ReadAllLines (address);

The code is written in CustomerDataAccess class DataAccess Layer.

Project File

The main problem with the method LoadAll Code:

   public ICollection<Customer> LoadAll()
{
    var alldata = File.ReadAllLines(address);

    List<Customer> lst = new List<Customer>();

    foreach (var s in alldata)
    {
        var objCustomer = customerSerializer.Deserialize(s);
        lst.Add(objCustomer);
    }

    return lst;
}

© Programmers or respective owner

Related posts about c#